export default {
	components: {

	},
	data() {
		return {
			waybill_type: 0,
			waybill_sn: '',
			waybillModel: {},
			logList: [],
		}
	},
	onLoad(options) {
		console.log(options) 
		if (options && options.waybill_sn) {
			this.waybill_sn = options.waybill_sn;
		}
		// var url = "http://tmsapidev1.chengxin56.net/weixin/?waybill_type=0&waybill_sn=Y12023051500007";
		const url = decodeURIComponent(options.q); // 获取到二维码原始链接内容
		this.handleData(url);
	},
	onShow() {
 
	},
	watch: {

	},
	methods: {
		handleData(urlstr) {
			if (!this.check.isNull(urlstr)) {
				var params = this.parseQueryString(urlstr);
				if (params && params.waybill_sn) {
					this.waybill_sn = params.waybill_sn;
				}
				if (params && params.waybill_type) {
					this.waybill_type = params.waybill_type;
				}
			}
			this.getWaybillInfo()
			this.getOrderListData();
		},
		parseQueryString(url) {
			var params = {};
			var arr = url.split("?");
			if (arr.length <= 1) {
				return params;
			}
			arr = arr[1].split("&");
			for (var i = 0, l = arr.length; i < l; i++) {
				var a = arr[i].split("=");
				params[a[0]] = a[1];
			}
			return params;
		},
		// 订单列表
		getOrderListData() {
			var source = '';
			if(this.waybill_type == 1){
				source = 'sf';
			}else{
				source = 'tms';
			}
			//waybill_type 1三方 0专线
			//source 来源sf:三方；tms专线
			var data = {
				waybill_sn: this.waybill_sn,
				source:source
			};
			this.http.sendRequest({
				api: this.api.order.scanGetWaybillLogApi,
				data: data,
				success: res => {
					
					let newArr = [];
					let msg = res.message;
					if (res.code == 1 && res.data) {
						newArr = res.data;
					} else {
						this.$util.showToast({
							title: msg
						});
					}
					//设置列表数据
					// if (mescroll.num == 1){
					this.logList = []; //如果是第一页需手动制空列表
					// } 
					this.logList = this.logList.concat(newArr); //追加新数据
					// console.log(this.logList);
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				},
				fail: res => {
					mescroll.endErr();
					if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
				}
			});
		},
		getWaybillInfo() {
			var source = '';
			if(this.waybill_type == 1){
				source = 'sf';
			}else{
				source = 'tms';
			}
			//waybill_type 1三方 0专线
			//source 来源sf:三方；tms专线
			var data = {
				waybill_sn: this.waybill_sn,
				source:source
			};
			this.http.sendRequest({
				api: this.api.order.scanGetWaybillInfoApi,
				data:data,
				success: res => {
					if (res.code == 1) {
						this.waybillModel = res.data;
					}
				},
				fail: res => {
					console.log('fail', res)
				}
			});
		},
	}

}